package com.cncsi.web;


import com.cncsi.entity.Restaurant;
import com.cncsi.service.RestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/restaurant")
public class RestaurantController {

    @Autowired
    private RestaurantService restaurantService;


    @RequestMapping("/toRestaurant")
    public String init(Map<String,Object> map){
        List<Restaurant> restaurantList =  restaurantService.getRestaurantList();
        map.put("restaurantList",restaurantList);
        List<Restaurant> restaurantAll = restaurantService.getRestaurantAll();
        map.put("restaurantAll",restaurantAll);
        return "restaurant/restaurant_index";
    }

    @ResponseBody
    @RequestMapping(value = "/saveRestaurant",method = RequestMethod.POST)
    public String saveRestaurant(Restaurant restaurant){
//        System.out.println(restaurant.getAddr());
//        String sts = "success";
        String sts = restaurantService.saveRestaurant(restaurant);
        return sts;
    }
}
